package com.wangchao.administrator.zenmechi.ui.fragment.shopfragment;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import com.wangchao.administrator.zenmechi.R;
import com.wangchao.administrator.zenmechi.bean.shopcategorybean.ShopCategoryResultBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/10/19.
 */
public class MyAdapterForShopExpand extends BaseExpandableListAdapter {

    private Context context;
    private List<ShopCategoryResultBean> list;

    public MyAdapterForShopExpand(Context context, List<ShopCategoryResultBean> list) {
        this.context = context;
        this.list = list;
    }


    @Override
    public int getGroupCount() {
        return list.size();
    }

    @Override
    public int getChildrenCount(int i) {
        return list.get(i).getChilds().size();
    }

    @Override
    public Object getGroup(int i) {
        return list.get(i);
    }

    @Override
    public Object getChild(int i, int i1) {
        return list.get(i).getChilds().get(i);
    }

    @Override
    public long getGroupId(int i) {
        return i;
    }

    @Override
    public long getChildId(int i, int i1) {
        return i1;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
        ViewHolder holder01 = null;
        if (view == null){
            view = LayoutInflater.from(context).inflate
                    (R.layout.shop_expand_list_item, viewGroup, false);
            holder01 = new ViewHolder(view);
            view.setTag(holder01);
        }else {
            holder01 = (ViewHolder) view.getTag();
        }

            holder01.tvShopExpand.setText(list.get(i).getName());

        return view;
    }

    @Override
    public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
        ViewHolder02 holder02 = null;
        if (view == null){
            view = LayoutInflater.from(context).inflate
                    (R.layout.shop_list_item, viewGroup, false);
            holder02 = new ViewHolder02(view);
            view.setTag(holder02);
        }else {
            holder02 = (ViewHolder02) view.getTag();
        }

            holder02.tvShopExpand.setText(list.get(i).getChilds().get(i1).getName());
        return view;
    }

    @Override
    public boolean isChildSelectable(int i, int i1) {
        return true;
    }

    static class ViewHolder {
        @BindView(R.id.tv_shop_expand)
        TextView tvShopExpand;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

    static class ViewHolder02 {
        @BindView(R.id.tv_shop_item)
        TextView tvShopExpand;

        ViewHolder02(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
